/**
 * Created by yyj on 2015/10/28.
 */
$(function(){
	//点击提交按钮
	$('.press_btn1.Sub').click(function(){
		
       	var index = parent.layer.getFrameIndex(window.name);
        var priId = $("#priId").val().trim();
        var priName=$("#priName").val().trim();
        var progCode=$("#progCode").val().trim();
        var priPrior = $("#priPrior").val().trim();
        var state=$("#state").val().trim();
        var remark=$("#remark").val().trim();
        var actionPri='';
        $("input[name='actionPri']:checked").each(function(){
        	actionPri+=$(this).val()+",";
        })
        if(actionPri.length>0){
        	actionPri=actionPri.substring(0,actionPri.length-1);
        }
        var showHideFlag = $("input[name='show_hide_flag']:checked").val();
        var reg = /^\d+$/;
        if(priName == "" || state == "" || priPrior == ""){
        	parent.layer.msg('带*号的不能为空！', {time:1300});
        }else if(!priPrior.match(reg)){
        	parent.layer.msg('优先级必须为数字！', {time:1500});
        }else if(priPrior == 0 || priPrior > 2147483647){
        	parent.layer.msg('输入的数字超出范围或不在范围内！', {time:2000});
        }else{
        	$.ajax({
            url:"editPrivilege.do",
            type:"post",
            dataType: 'json',
            data:{
            	"priId":priId,
        		"priName":priName,
        		"progCode":progCode,
        		"priPrior":priPrior,
        		"state":state,
        		"remark":remark,
        		"actionPri":actionPri,
        		"oldActionPri":$("#actionPri").val(),
        		"showHideFlag":showHideFlag
            },
            success:function(result){
                if(result.data){
                	parent.flashTreeNode();
                	parent.paging(1);
                	parent.$('.checkAll').removeAttr('checked');
                    parent.layer.msg('修改成功', {time:1300});
       			 	parent.layer.close(index);
                }else{
                    parent.layer.msg('修改失败！', {time:1000});
                }
            }
        });
        }
        
        
        
    })

    //点击关闭按钮
    $('.press_btn2.Close').click(function(){
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
        parent.$('.checkAll').removeAttr('checked');
    })
    //点击添加兄弟按钮
     $('.press_btn1.KeepBrother').click(function(){
        var index = parent.layer.getFrameIndex(window.name);
        var priId = $("#priId").val().trim();
        var priName=$("#priName").val().trim();
        var progCode=$("#progCode").val().trim();
        var priPrior = $("#priPrior").val().trim();
        var state=$("#state").val().trim();
        var remark=$("#remark").val().trim();
        var actionPri='';
        $("input[name='actionPri']:checked").each(function(){
        	actionPri+=$(this).val()+",";
        })
        if(actionPri.length>0){
        	actionPri=actionPri.substring(0,actionPri.length-1);
        }
        var showHideFlag = $("input[name='show_hide_flag']:checked").val();
        var reg = /^\d+$/;
        if(priName == "" || state == "" || priPrior == ""){
        	parent.layer.msg('带*号的不能为空！', {time:1300});
        }else if(!priPrior.match(reg)){
        	parent.layer.msg('优先级必须为数字！', {time:1500});
        }else if(priPrior == 0 || priPrior > 2147483647){
        	parent.layer.msg('输入的数字超出范围或不在范围内！', {time:2000});
        }else{
        	$.ajax({
            url:"addBroPrivilege.do",
            type:"post",
            dataType: 'json',
            data:{
            	"priId":priId,
        		"priName":priName,
        		"progCode":progCode,
        		"priPrior":priPrior,
        		"state":state,
        		"remark":remark,
        		"actionPri":actionPri,
        		"showHideFlag":showHideFlag
            },
            success:function(result){
                if(result.data){
                	parent.flashTreeNode();
                	parent.paging(1);
                	parent.$('.checkAll').removeAttr('checked');
                    parent.layer.msg('添加成功', {time:1300});
       			 	parent.layer.close(index);
                }else{
                    parent.layer.msg('添加失败！', {time:1000});
                }
            }
        });
        }
        
        
        
    })
    
    
    //点击添加子按钮
     $('.press_btn1.KeepChild').click(function(){
        var index = parent.layer.getFrameIndex(window.name);
        var priId = $("#priId").val().trim();
        var priName=$("#priName").val().trim();
        var progCode=$("#progCode").val().trim();
        var priPrior = $("#priPrior").val().trim();
        var state=$("#state").val().trim();
        var remark=$("#remark").val().trim();
        var reg = /^\d+$/;
        var actionPri='';
        $("input[name='actionPri']:checked").each(function(){
        	actionPri+=$(this).val()+",";
        })
        if(actionPri.length>0){
        	actionPri=actionPri.substring(0,actionPri.length-1);
        }
        var showHideFlag = $("input[name='show_hide_flag']:checked").val();
        if(priName == "" || state == "" || priPrior == ""){
        	parent.layer.msg('带*号的不能为空！', {time:1300});
        }else if(!priPrior.match(reg)){
        	parent.layer.msg('优先级必须为数字！', {time:1500});
        }else if(priPrior == 0 || priPrior > 2147483647){
        	parent.layer.msg('输入的数字超出范围或不在范围内！', {time:2000});
        }else{
        	$.ajax({
            url:"addChildPrivilege.do",
            type:"post",
            dataType: 'json',
            data:{
            	"priId":priId,
        		"priName":priName,
        		"progCode":progCode,
        		"priPrior":priPrior,
        		"state":state,
        		"remark":remark,
        		"actionPri":actionPri,
        		"showHideFlag":showHideFlag
            },
            success:function(result){
            	if(result.msg!=""){
            		parent.layer.msg(result.msg, {time:1300});
            	}else{
            		if(result.data){
                		parent.flashTreeNode();
                		parent.paging(1);
                		parent.$('.checkAll').removeAttr('checked');
                    	parent.layer.msg('添加子节点成功', {time:1300});
       			 		parent.layer.close(index);
               		}else{
                    	parent.layer.msg('添加子节点失败！', {time:1000});
                	}
            	}
            }
        });
        }
        
        
        
    })
    
});

